package com.dingding.commonservice.core.company.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.dingding.common.core.beans.Organization;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.commonservice.core.company.dao.ICompanyDao;
import com.dingding.commonservice.core.company.service.ICompanyService;
import com.dingding.facade.commonservice.common.dto.company.ReqGetCompanyDTO;
import com.dingding.facade.commonservice.common.dto.company.ReqGetCompanyListDTO;
import com.dingding.facade.commonservice.common.dto.company.ResGetCompanyListDTO;

/**
 * 
 * @ClassName: CompanyServiceImpl 
 * @Description: 公司业务逻辑实现类
 * @author YHQ
 * @date 2016年12月1日 下午5:55:11
 * @since V2.5.7
 * 
 */
@Component("companyService")
public class CompanyServiceImpl implements ICompanyService{

	private Logger log = Logger.getLogger(this.getClass());
	
	@Resource(name = "companyDao")
	private ICompanyDao companyDao;
	
	/**
	 * 
	 * @Title: getCompanyListDTOs 
	 * @Description: 根据城市Id获取公司列表
	 * @param reqGetCompanyListDTO 
	 * @author YHQ 
	 * @since V2.5.7
	 * @return List<ResGetCompanyListDTO>    返回类型
	 * 
	 */
	public List<ResGetCompanyListDTO> getCompanyListDTOs(ReqGetCompanyListDTO reqGetCompanyListDTO) {
		
		if(reqGetCompanyListDTO == null || !ToolUtil.validateParam(reqGetCompanyListDTO)){
			log.error("客户端请求参数为空");
			return null;
		}
		
		return companyDao.getCompanyListDTOs(reqGetCompanyListDTO.getCityId());
	}

	@Override
	public ResGetCompanyListDTO getCompanyDTOById(ReqGetCompanyDTO reqGetCompanyDTO) {
		
		if(reqGetCompanyDTO == null || !ToolUtil.validateParam(reqGetCompanyDTO)){
			log.error("客户端请求参数为空");
			return null;
		}
		
		return companyDao.getCompanyDTOById(reqGetCompanyDTO.getOrganizationId());
	}

	@Override
	public Organization getOrganizationById(Integer organizationId) {
		
		if(organizationId == null) {
			return null;
		}
		
		return companyDao.getOrganizationById(organizationId);
	}

}
